package com.ruoyi.common.utils.junit;

import cn.hutool.json.JSONUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class JunitAdminUtils {

    public static void get(String url) {
        String token = JunitUtils.login();
        get(url, token);
    }

    public static void put(String url, Object reqObj) {
        String token = JunitUtils.login();
        put(url, reqObj, token);
    }

    public static void post(String url, Object reqObj) {
        String token = JunitUtils.login();
        post(url, reqObj, token);
    }

    public static void get(String url, String token) {
        AjaxResult ajaxResult = JunitUtils.jUnitGet(url, AjaxResult.class, token, null);
        log.info("\nresult:\n\t{}", ajaxResult);
    }

    public static void put(String url, Object reqObj, String token) {
        String req = JSONUtil.toJsonStr(reqObj);
        AjaxResult ajaxResult = JunitUtils.jUnitPut(url, req, AjaxResult.class, token, null);
        log.info("\nresult:\n\t{}", ajaxResult);
    }

    public static void post(String url, Object reqObj, String token) {
        String req = JSONUtil.toJsonStr(reqObj);
        AjaxResult ajaxResult = JunitUtils.jUnitPost(url, req, AjaxResult.class, token, null);
        log.info("\nresult:\n\t{}", ajaxResult);
    }

}
